import SingletonClass from '../common/base/SingletonClass'
import EventDispatch, { Event_Name } from "../common/event/EventDispatch";


export default class Model extends SingletonClass {
    static ins() {
        return super.ins() as Model;
    }

    public contactSounds: number = 0

    // 初始小球数
    private _ballInitCount = 2
    public get ballInitCount() {
        return this._ballInitCount
    }
    public set ballInitCount(val: number) {
        val = val < 2 ? 2 : val;
        this._ballInitCount = val;
    }


    // 初始坐标
    readonly ballInitX = 0;
    readonly ballInitY = -400;
    // 球速
    private _ballSpeed = 1000
    public get ballSpeed() {
        return this._ballSpeed
    }
    public set ballSpeed(val) {
        this._ballSpeed = val
    }

    // 发射速度
    private _ballFireSpeed = 2
    public set ballFireSpeed(value) {
        value = value < 2 ? 2 : value;
        this._ballFireSpeed = value;
    }
    public get ballFireSpeed() {
        return this._ballFireSpeed;
    }

   


    private _ball_power = 1
    public set ball_power(value) {
        // 改变球的权重
        const oldValue = this._ball_power
        value = value < 1 ? 1 : value;
        this._ball_power = value;
        // 发出事件
        EventDispatch.ins().fire(Event_Name.GAME_BALL_POWER_CHANGED, oldValue, value);
    }
    public get ball_power() {
        return this._ball_power;
    }

    readonly theme_config: { color: cc.Color[], theme: string }[] = [
        {
            color: [
                cc.color(0, 232, 231), cc.color(0, 232, 132), cc.color(0, 232, 52), cc.color(125, 232, 52), cc.color(190, 190, 50),
                cc.color(150, 220, 40), cc.color(230, 215, 40), cc.color(230, 80, 20), cc.color(228, 35, 20), cc.color(228, 0, 20)
            ],
            theme: 'theme0'
        }
    ]


    private _score = 0;
    public set score(value) {
        value = value < 0 ? 0 : value;
        const oldValue = this._score;
        this._score = value;
        EventDispatch.ins().fire(Event_Name.GAME_SCORE_CHANGED, oldValue, value);
    }
    public get score() {
        return this._score;
    }


    private _revive_times = 0;
    public set revive_times(value) {
        value = value < 0 ? 0 : value;
        this._revive_times = value;
    }
    public get revive_times() {
        return this._revive_times;
    }

    public reset() {
        this.score = 0;
        this.revive_times = 0;
        this._ballInitCount =  2;
        this._ballFireSpeed =  1;
        this.ball_power = 1;
    }

    private _fireBallDt = 2;
    public set fireBallDt(value) {
        value = value < 2 ? 2 : value;
        this._fireBallDt = value;
    }
    public get fireBallDt() {
        return this._fireBallDt;
    }


     // 障碍信息
    readonly brickRadius = 43
    readonly brickInitX = 0
    readonly brickInitY = 500
    readonly max_ball_init_count = 60;
    readonly max_ball_fire_speed = 10;

    readonly theme_price = 500;
    readonly sign_interval_sec = 3600;

    
    readonly brick_type_percent = [
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,//正方形
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        1, 1, 1, 1, 1, 1,//圆
        2, 2, 2, 2, 2, //六边形
        3,  //三角1
        4,  //三角2
        5,  //三角3
        6,  //三角4
        7, 7, 7, 7, 7, 7, 7, 7, 7,  //球
        8, 8,  //星1 正
        9,   //星1 圆
        10, //星2 六
        // 11, //道具1
        // 12, //道具2
        // 13  //道具3
    ];
}
